<?php
function jd($list,$id=0){
    $arr=[];
    foreach ($list as $key => $value) {
        if ($value['pid']==$id) {
            $value['son']=jd($list,$value['id']);
            $arr[]= $list[$key];
        }
    }
    return $arr;
}
function fjd($list,$pid=0){
    $arr=[];
    foreach ($list as $key => $value) {
        if ($value['id']==$pid) {
            $arr[]= $list[$key];
            fjd($list,$value['pid']);
        }
    }
    return $arr;
}